import axios from "axios";
// 引入进度条
import nprogress from "nprogress";

import 'nprogress/nprogress.css';

import detail from '@/store/detail'
import user from '@/store/user'


console.log(nprogress);

const requests = axios.create({
  baseURL: '/api',
  timeout: 5000
})

requests.interceptors.request.use((config) => {
  console.log(detail);
  if (detail.state.uuid_token) {
    config.headers.userTempId = detail.state.uuid_token
  }
  if (user.state.token) {
    config.headers.token = user.state.token
  }

  nprogress.start()
  return config
})

requests.interceptors.response.use((res) => {
  nprogress.done()
  return res.data

}, (error) => {
  return Promise.reject(new Error('faile'))
})

export default requests